home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / wings / w2_src / pd_menu.c < prev    next >
C/C++ Source or Header  |  1994-11-16  |  4KB  |  154 lines

  1. #define    PD_MENU
  2. #include <egb.h>
  3. #include <mos.h>
  4. #include <string.h>
  5. #include <msdos.cf>
  6. #include "define.h"
  7. #include "module.h"
  8. #include "extend.h"
  9. #include "pd_menu.h"
  10. #include "font_sub.h"
  11. // プルダウンメニュー用拡張関数
  12.  
  13. #define    BG_COLOR 8
  14. #define    ITEM_ON 8
  15. #define    ITEM_OFF 4
  16.  
  17.  
  18. // プルダウンメニューのアイテムアドレスを計算する
  19. void    PDM_make_item_adress( struct PD_menu *menu, int *adr )
  20. {
  21.  
  22.     int        i;
  23.     
  24.     for( i=0;i<=menu->n-1;i++ ){
  25.         *( adr + (i*4)+0 ) = menu->item.x[ i ] = menu->x+6;
  26.         *( adr + (i*4)+1 ) = menu->item.y[ i ] = menu->y+4+(i*16);
  27.         *( adr + (i*4)+2 ) = menu->x + 6 + ( menu->len * 6 ) - 1;
  28.         *( adr + (i*4)+3 ) = menu->y + 4 + ( i * 16 ) + 15;
  29.     }
  30.     // 終端ターミネータ
  31.     *( adr + menu->n*4+0 ) = 0;
  32.     *( adr + menu->n*4+1 ) = 0;
  33.     *( adr + menu->n*4+2 ) = 0;
  34.     *( adr + menu->n*4+3 ) = 0;
  35.     return;
  36.  
  37. }
  38. // プルダウンメニューを表示する
  39. void    PDM_display
  40. ( char *egbwork, char *strptn, struct PD_menu *menu, int *flag, int n )
  41. {
  42.  
  43.     int        i, x, y, x1, y1, x2, y2, PAGE, col[ ] = { ITEM_OFF, ITEM_ON };
  44.     UINT    egb_sel;
  45.     
  46.     egb_sel = getds( );
  47.     PAGE = ( EGB_getWritePage( egbwork, egb_sel ) ) ? PAGE_1 : PAGE_0;
  48.     x1 = menu->x;
  49.     y1 = menu->y;
  50.     x2 = menu->x + ( menu->len * 6 ) + 11;
  51.     y2 = menu->y + ( menu->n * 16 ) + 7;
  52.     getimage( egbwork, x1, y1, x2, y2, n );
  53.     box( egbwork, x1  , y1  , x2  , y2  ,  BG_COLOR );
  54.     box( egbwork, x1+1, y1+1, x2-3, y2-3,        15 );
  55.     for( i=0;i<=menu->n-1;i++ ){
  56.         x = menu->item.x[ i ];
  57.         y = menu->item.y[ i ]+2;
  58.         font_ank_col( col[ *( flag + i ) ], 15 );
  59.         font_kan_col( col[ *( flag + i ) ], 15 );
  60.         font_mix( strptn, PAGE, POS( x, y ), menu->item.str[ i ], 0 );
  61.     }
  62.     return;
  63.  
  64. }
  65. // プルダウンメニューを消去する
  66. void    PDM_erase( char *egbwork, struct PD_menu *menu, int n )
  67. {
  68.  
  69.     int        x1, y1, x2, y2;
  70.     
  71.     x1 = menu->x;
  72.     y1 = menu->y;
  73.     x2 = menu->x + ( menu->len * 6 ) + 11;
  74.     y2 = menu->y + ( menu->n * 16 ) + 7;
  75.     putimage( egbwork, x1, y1, x2, y2, n );
  76.     return;
  77.  
  78. }
  79. // プルダウンメニューの押された番号を返す
  80. int        PDM_get_item_adress( int *adr, int x, int y )
  81. {
  82.  
  83.     int        i = 0;
  84.     
  85.     while( *( adr + i )+*( adr + i+1 )+*( adr + i+2 )+*( adr + i+3 ) ){
  86.         if( cmp( x, *( adr + i ), *( adr + i+2 ) )
  87.                 && cmp( y, *( adr + i+1 ), *( adr + i+3 ) ) )
  88.             return( i/4 );
  89.         i += 4;
  90.     }
  91.     return( -1 );
  92.  
  93. }
  94. // プルダウンメニューのタイトルを表示
  95. void    PDM_display_title( char *egbwork, char *strptn, struct PD_menu *menu )
  96. {
  97.  
  98.     int        len, PAGE;
  99.     UINT    egb_sel;
  100.     
  101.     egb_sel = getds( );
  102.     PAGE = ( EGB_getWritePage( egbwork, egb_sel ) ) ? PAGE_1 : PAGE_0;
  103.     strcat( menu->title, " ▼" );
  104.     len = strlen( menu->title ) + 4;
  105.     box( egbwork, menu->x, 0, menu->x+len*6-1, 19, BG_COLOR );
  106.     button_off( egbwork, menu->x, 0, menu->x+len*6-1, 19 );
  107.     font_ank_col( 15, BG_COLOR );
  108.     font_kan_col( 15, BG_COLOR );
  109.     font_mix( strptn, PAGE, POS( menu->x+12, 4 ), menu->title, 0 );
  110.     return;
  111.  
  112. }
  113. // プルダウンメニューのタイトルボタンをON
  114. void    PDM_title_on( char *egbwork, struct PD_menu *menu )
  115. {
  116.  
  117.     int        len;
  118.  
  119.     len = strlen( menu->title ) + 4;
  120.     button_on( egbwork, menu->x, 0, menu->x+len*6-1, 19 );
  121.  
  122. }
  123. // プルダウンメニューのタイトルボタンをOFF
  124. void    PDM_title_off( char *egbwork, struct PD_menu *menu )
  125. {
  126.  
  127.     int        len;
  128.  
  129.     len = strlen( menu->title ) + 4;
  130.     button_off( egbwork, menu->x, 0, menu->x+len*6-1, 19 );
  131.  
  132. }
  133. // プルダウンメニューのアイテムをクリック
  134. void
  135. PDM_item_clic( char *egbwork, char *strptn, struct PD_menu *menu, int n )
  136. {
  137.  
  138.     int        pdm_x, pdm_y, PAGE;
  139.     UINT    egb_sel;
  140.     
  141.     egb_sel = getds( );
  142.     PAGE = ( EGB_getWritePage( egbwork, egb_sel ) ) ? PAGE_1 : PAGE_0;
  143.     MOS_sleep;
  144.     pdm_x = menu->item.x[ n ];
  145.     pdm_y = menu->item.y[ n ]+2;
  146.     font_ank_col( 15, BG_COLOR );
  147.     font_kan_col( 15, BG_COLOR );
  148.     font_mix( strptn, PAGE, POS( pdm_x, pdm_y ), menu->item.str[ n ], 0 );
  149.     mos_loop( 1 );
  150.     sleep( 10 );
  151.     MOS_awake;
  152.  
  153. }
  154.